package iso3.pt.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;

import iso3.pt.model.Alumno;
import iso3.pt.model.Asignatura;
import iso3.pt.model.Evaluacion;
import iso3.pt.model.Unidad;
import iso3.pt.service.PtDaoService;

public class SubjectAction extends ActionSupport implements Preparable{
	
	private Alumno alu;
	private Asignatura asig;
	private int asigID;
	private int aluID;
	private String concepto;
	private float mark;
	private List<Evaluacion> listaEval;
	private Set<Evaluacion> evaluationSet;
	private List<Unidad> listaUd;
	private PtDaoService dao = null;
	
	
	@Override
	public void prepare() throws Exception {
		if (dao == null){
			dao = new PtDaoService();
		}		
		asig = dao.getAsignatura(asigID);
	}
	
	public String doShowSubjectUnits(){
		listaUd = new ArrayList<Unidad>();
		for (Unidad ud : dao.getUnidades(asigID)){
			listaUd.add(ud);
		}
		return "UnitList";
	}
	
	public String doShowAllMarks(){
		alu = (Alumno)ActionContext.getContext().getSession().get("logged");
		aluID = alu.getId();
		listaEval = dao.getEvaluacionesOrderedByAsignatura(aluID);
		return "allMarks";
	}
	
	public String doShowMarks(){
		alu = (Alumno)ActionContext.getContext().getSession().get("logged");
		aluID = alu.getId();
		int subjectId = Integer.parseInt(((String[])ActionContext.getContext().getParameters().get("subjectId"))[0]);
		asig = dao.getAsignatura(subjectId);
		setEvaluationSet(dao.getEvaluaciones(subjectId,aluID));
		return "marks";
	}

	
	public Alumno getAlu() {
		return alu;
	}

	public void setAlu(Alumno alu) {
		this.alu = alu;
	}
	
	public Asignatura getAsig() {
		return asig;
	}

	public void setAsig(Asignatura asig) {
		this.asig = asig;
	}

	public int getAsigID() {
		return asigID;
	}

	public void setAsigID(int asigID) {
		this.asigID = asigID;
	}

	public int getAluID() {
		return aluID;
	}

	public void setAluID(int aluID) {
		this.aluID = aluID;
	}

	public String getConcepto() {
		return concepto;
	}

	public void setConcepto(String concepto) {
		this.concepto = concepto;
	}

	public float getMark() {
		return mark;
	}

	public void setMark(float mark) {
		this.mark = mark;
	}

	public List<Evaluacion> getListaEval() {
		return listaEval;
	}

	public void setListaEval(List<Evaluacion> listaEval) {
		this.listaEval = listaEval;
	}

	public List<Unidad> getListaUd() {
		return listaUd;
	}

	public void setListaUd(List<Unidad> listaUd) {
		this.listaUd = listaUd;
	}

	public PtDaoService getDao() {
		return dao;
	}

	public void setDao(PtDaoService dao) {
		this.dao = dao;
	}

	public void setEvaluationSet(Set<Evaluacion> evaluationSet) {
		this.evaluationSet = evaluationSet;
	}

	public Set<Evaluacion> getEvaluationSet() {
		return evaluationSet;
	}
	
	
}
